// webpack默认配置
const defaultSplitChunks = {
    chunks: 'async',// 默认是async
    minSize: 30000, // 生成 chunk 的最小体积（以 bytes 为单位），默认值为30000.
    // maxSize:0, // chunk超过该大小，webpack会尝试将其分隔成较小的部分，默认为0.
    minRemainingSize: 0,
    minChunks: 1, // 要被提取的模块最小被引用次数，引用次数大于等于minChunks值，才能被提取
    maxAsyncRequests: 30, // 最大异步请求数量
    maxInitialRequests: 30, // 入口点处的最大并行请求数(入口文件加载后，还能同时加载的js文件数量，包括入口文件)
    // automaticNameDelimiter: '~', // 打包生成的js文件名分隔符
    // 强制拆分的大小临界值，其他限制(minRemainingSize,maxAsyncRequests,maxInitialRequests)将被忽略
    // enforceSizeThreshold: 50000, 
    // 分包规则：重点
    cacheGroups: {
        vendors: {
            name: 'chunk-vendors', // 拆分 chunk 的名称
            // unix平台下：/node_modules/、window平台下：\node_modules\
            test: /[\\/]node_modules[\\/]/,
            priority: -10,
            chunks: 'initial', // async, initial, all
        },
        default: { // 配置default组，则默认chunk的name为'entry'的入口名，即'vueApp'
            name: 'default-chunk',
            minChunks: 2,
            priority: -20,
            reuseExistingChunk: true,
            chunks: 'initial'
        },
    },
};
// @vue/cli默认配置
const vueCliSplitChunks = {
    chunks: 'async', // 默认是async
    cacheGroups: {
        vendors: {
            name: 'chunk-vendors',
            // unix平台下：/node_modules/、window平台下：\node_modules\
            test: /[\\/]node_modules[\\/]/,
            priority: -10,
            chunks: 'initial', // async, initial, all
        },
        common: {
            name: 'chunk-common',
            minChunks: 2,
            priority: -20,
            chunks: 'initial',
            reuseExistingChunk: true
        }
    }
};
// 项目优化的splitChunks
const optimizeSplitChunks = {
    chunks: 'async', // 默认是async
    cacheGroups: {
        // vendors: { // react基本框架等
        //     name: 'chunk-vendors',
        //     test: /(react|react-dom|react-dom-router|redux|prop-types)/,
        //     priority: 100,
        //     chunks: 'initial',
        // },
        'vendors': { // vue基本框架
            name: 'chunk-vendors',
            test: /(vue|vuex|vue-router)/,
            priority: 10,
            chunks: 'initial',
        },
        // 'echarts-lib': { // 异步加载echarts包
        //     name: 'echarts-lib',
        //     test: /(echarts|zrender)/,
        //     priority: 10,
        //     chunks: 'async'
        // },
        common: {
            name: 'chunk-common',
            minChunks: 2,
            priority: -20,
            chunks: 'initial',
            reuseExistingChunk: true
        }
    }
};

module.exports = {
    defaultSplitChunks,
    vueCliSplitChunks,
    optimizeSplitChunks
}